using DealerPlatform.Core.Consts;
using DealerPlatform.Service.OrderApp;
using DealerPlatform.Service.OrderApp.Dtos;
using DealerPlatform.Service.ProductApp;
using DealerPlatform.Service.ShoppingCartApp;
using DealerPlatform.Service.ShoppingCartApp.Dtos;
using DealerPlatform.Web.Filters;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace DealerPlatform.Web.Controllers;

[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
[CtmAuthorizationFilter]
public class OrderConfirmController(
    IShoppingCartAppService shoppingCartAppService,
    IProductService productService,
    IOrderService orderService) : BaseController
{
    [HttpGet]
    public async Task<IEnumerable<ShoppingCartDto>> Get()
    {
        var customerNo = HttpContext.Items[HttpContextItemKeyName.CUSTOMER_NO].ToString();
        var carts = (await shoppingCartAppService.GetShoppingCartDtos(customerNo)).Where(m => m.CartSelected);
        return carts;
    }

    [HttpPost]
    public async Task<string> Add(OrderMasterInputDto input)
    {
        var customerNo = HttpContext.Items[HttpContextItemKeyName.CUSTOMER_NO].ToString();
        var carts = (await shoppingCartAppService.GetShoppingCartDtos(customerNo)).Where(m => m.CartSelected).ToList();
        return await orderService.AddOrder(customerNo, input, carts);
    }
    
}